package com.atguigu.ssyx.product.controller;


import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.model.product.AttrGroup;
import com.atguigu.ssyx.product.service.AttrGroupService;
import com.atguigu.ssyx.vo.product.AttrGroupQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 属性分组 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2025-10-30
 */
@Api(tags = "属性分组")
@RestController
@RequestMapping("/admin/product/attrGroup")
public class AttrGroupController {

    @Resource
    private AttrGroupService attrGroupService;

    // 获取属性分组列表
    @ApiOperation("获取属性分组列表")
    @GetMapping("{page}/{limit}")
    public Result index(@PathVariable Long page,
                             @PathVariable Long limit,
                             AttrGroupQueryVo attrGroupQueryVo) {
        Page<AttrGroup> pageParam = new Page<>(page, limit);
        Page<AttrGroup> pageModel = attrGroupService.selectPageAttrGroup(pageParam, attrGroupQueryVo);
        return Result.ok(pageModel);
    }

    // 获取所有属性分组列表
    @ApiOperation("获取所有属性分组列表")
    @GetMapping("findAllList")
    public Result findAllList() {
        List<AttrGroup> list = attrGroupService.findAllAttrGroup();
        return Result.ok(list);
    }

    // 根据id查询属性分组
    @ApiOperation("根据id查询属性分组")
    @GetMapping("get/{id}")
    public Result get(@PathVariable Long id) {
        AttrGroup attrGroup = attrGroupService.getById(id);
        return Result.ok(attrGroup);
    }

    // 添加属性分组
    @ApiOperation("添加属性分组")
    @PostMapping("save")
    public Result save(@RequestBody AttrGroup attrGroup) {
        boolean save = attrGroupService.save(attrGroup);
        return Result.ok(save);
    }

    // 修改属性分组
    @ApiOperation("修改属性分组")
    @PutMapping("update")
    public Result updateById(@RequestBody AttrGroup attrGroup) {
        boolean update = attrGroupService.updateById(attrGroup);
        return Result.ok(update);
    }

    // 删除属性分组
    @ApiOperation("删除属性分组")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id) {
        boolean remove = attrGroupService.removeById(id);
        return Result.ok(remove);
    }

    // 批量删除属性分组
    @ApiOperation("批量删除属性分组")
    @DeleteMapping("batchRemove")
    public Result batchRemove(@RequestBody List<Long> idList) {
        boolean remove = attrGroupService.removeByIds(idList);
        return Result.ok(remove);
    }
}

